package com.sparrow.common.attr.domain;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 属性实例,标识属性路径
 */
public class AttrModuleInst {
    public final AttrModuleInst parent;
    public final List<AttrModuleInst> childList = new ArrayList<>();
    public final AttrModule module;
    public final Object id;  // keys 可以是 Integer、String、数组等

    public AttrModuleInst(AttrModuleInst parent, AttrModule module, Object id) {
        this.parent = parent;
        this.module = module;
        this.id = id;
        if (parent != null) {
            parent.childList.add(this);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        AttrModuleInst inst = (AttrModuleInst) o;
        return Objects.equals(parent, inst.parent) &&
                Objects.equals(module, inst.module) &&
                Objects.equals(id, inst.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(parent, module, id);
    }


    @Override
    public String toString() {
        return "属性实例{" + "module=" + module.name + " 实例id=" + id + '}';
    }
}
